﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace FuncWorks.Xna.UI
{
	public class TextStyle
	{
		#region Fields / Properties
		public SpriteFont SpriteFont { get; private set; }
		public Color Color { get; private set; }
		public Color? ShadowColor { get; private set; }
		public int? ShadowDepth { get; private set; }
		public AnchorPoint? ShadowDirection { get; private set; }

		int shadowX { get; set; }
		int shadowY { get; set; }
		#endregion

		#region Constructors
		public TextStyle(SpriteFont spriteFont, Color color)
		{
			SpriteFont = spriteFont;
			Color = color;
			shadowY = 0;
			shadowX = 0;
		}

		public TextStyle(SpriteFont spriteFont, Color color, Color shadowColor, int shadowDepth, AnchorPoint shadowDirection)
		{
			SpriteFont = spriteFont;
			Color = color;
			ShadowColor = shadowColor;
			ShadowDepth = shadowDepth;
			ShadowDirection = shadowDirection;

			shadowY = 0;
			shadowX = 0;
			switch (ShadowDirection)
			{
				case AnchorPoint.BottomLeft:
					shadowX = (int)ShadowDepth * -1;
					shadowY = (int)ShadowDepth;
					break;

				case AnchorPoint.BottomRight:
					shadowX = (int)ShadowDepth;
					shadowY = (int)ShadowDepth;
					break;

				case AnchorPoint.TopLeft:
					shadowX = (int)ShadowDepth * -1;
					shadowY = (int)ShadowDepth * -1;
					break;

				case AnchorPoint.TopRight:
					shadowX = (int)ShadowDepth;
					shadowY = (int)ShadowDepth * -1;
					break;
			}
		}
		#endregion

		#region Public Methods
		public void DrawString(SpriteBatch spriteBatch, string text, Vector2 position)
		{
            if (text == null) { return; }
			if (ShadowDirection != null)
			{
				spriteBatch.DrawString(SpriteFont, text, new Vector2(position.X + shadowX, position.Y + shadowY), (Color)ShadowColor);
			}
			spriteBatch.DrawString(SpriteFont, text, position, Color);
		}

		public Vector2 MeasureString(string text)
		{
            if (text == null) { return new Vector2(0, 0); }
			Vector2 size = SpriteFont.MeasureString(text);
			if (ShadowDepth != null)
			{
				return new Vector2(size.X + (int)ShadowDepth, size.Y + (int)ShadowDepth);
			}
			else
			{
				return size;
			}
		}
		#endregion

	}
}
